'''
Created on 2011-08-29

@author: Olivier
'''
import Core
import types

class Connection(object):
    '''
    classdocs
    '''

    UNCONNECTED = "UNCONNECTED"
    
    _idList = list()

    _name = ""
    _parentSystem = Core.System.System()
    #Relative to parent system
    _position = (0,0)
    _linkConnection = UNCONNECTED
    _id = 0

    def __init__(self, name = "", parent = Core.System.System(), _linkConnection = Core.Link.Link(), position = (0,0)):
        '''
        Constructor
        '''
        #Set name
        self.setName(name)
        #Set parent system
        if type(parent) == type(Core.System.System):
            self._parentSystem = parent
        else:
            raise ValueError("parent must be a system but is " + str(type(parent)))
        #Set position
        self.setPosition(position)
        #Set ID
        self._generateIDNumber()
        
    def setPosition(self, position = (0,0)):
        """
        """
        if type(position) is types.TupleType:
            if len(position) is 2:
                self._position = position
            else:
                raise ValueError("position must be a tuple of length 2 but is of length " + str(len(position)))
        else:
            raise ValueError("position must be a tuple but is " + str(type(position)))
        
    def _generateIDNumber(self):
        """
        """
        if len(self._idList) == 0:
            self._id = 0
            self._idList.append(0)
        else:
            self._id = self._idList[-1] + 1
            self._idList.append(self._id)
            
    def getID(self):
        """
        """
        return self._id
        
    def getPosition(self):
        """
        """
        return self._position
    
    def setName(self, name = ""):
        """
        """        
        if type(name) == types.StringType:
            self._name = name
        else:
            raise ValueError("name must be a string but is " + str(type(name)))
        
    def getName(self):
        """
        """
        return self._name
    
    def setLinkConection(self, link = Core.Link.Link()):
        """
        """
        if type(link) == type(Core.Link.Link) or link == self.UNCONNECTED:
            self._linkConnection = link
        else:
            raise ValueError("link must be a Link but is " + str(type(link)))
        
    def getLinkConnection(self):
        """
        """
        return self._linkConnection
    